﻿using Publicuse.Entity.AttributeUtil;
using Publicuse.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Service.Extend
{
    public class ConstantSqlString<T>
    {
        private static string FindSql = null;

        static ConstantSqlString()
        {
            Type type = typeof(T);
            var tablename = TableAtributeUtil.GetTable<T>();
            FindSql = $"Select {string.Join(',', type.GetPropertiesWithNoQuery().Select(c => $"{c.Name}").ToList())} from {tablename}";
        }

        /// <summary>
        /// GetSql语句
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetFindSql(int id)
        {
            return $"{FindSql} where id={id}";
        }

        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public static string GetQuertSql(string exp)
        {
            return $"{FindSql} where {exp}";
        }
    }
}
